﻿@model ProductView


<div class="layui-container" style="margin-top:50px;margin-bottom:150px">
    @*不要from提交*@
    <form class="layui-form" id="addFrom" onsubmit="return false">

        <div class="layui-form-item">
            <!--用户名-->
            <label class="layui-form-label">名字</label>
            <div class="layui-input-inline">
                <input type="text" asp-for="Name" class="layui-input" />
                <span asp-validation-for="Name" style="color: #F56C6C"></span>
            </div>
        </div>
        @*上传图片*@
        <div class="layui-form-item">
            <label class="layui-form-label">上传图片</label>
            <div class="layui-input-block">
                <input type="file" asp-for="PicUrl" name="PicUrl" />
                <span asp-validation-for="PicUrl" style="color: #F56C6C"></span>
                <input type="hidden" id="PicUrl" />
            </div>
        </div>
        @*填充图片的位置*@
        <div class="layui-form-item">
            <div class="layui-input-block">
                <img id="imgPhoto" class="layui-upload-img" style="width:180px; height:140px" />
            </div>
        </div>
        @*材质*@
        <div class="layui-form-item">
            <label class="layui-form-label">材质</label>
            <div class="layui-input-inline">
                <input type="text" asp-for="CaiZhi" class="layui-input" />
                <span asp-validation-for="CaiZhi" style="color: #F56C6C"></span>
                @*<input type="text" id="CaiZhi" class="layui-input" />*@
            </div>
        </div>
        @*产品售价*@
        <div class="layui-form-item">
            <label class="layui-form-label">产品售价</label>
            <div class="layui-input-inline">
                <input type="text" asp-for="ProductPrice" class="layui-input" />
                <span asp-validation-for="ProductPrice" style="color: #F56C6C"></span>
                @*<input type="text" id="ProductPrice" class="layui-input" />*@
            </div>
        </div>
        @*市场售价*@
        <div class="layui-form-item">
            <label class="layui-form-label">市场售价</label>
            <div class="layui-input-inline">
                <input type="text" asp-for="MarketPrice" class="layui-input" />
                <span asp-validation-for="MarketPrice" style="color: #F56C6C"></span>
                @*<input type="text" id="MarketPrice" class="layui-input" />*@
            </div>
        </div>
        @*品牌*@
        <div class="layui-form-item">
            <label class="layui-form-label">品牌</label>
            <div class="layui-input-inline">
                <input type="text" asp-for="Brand" class="layui-input" />
                <span asp-validation-for="Brand" style="color: #F56C6C"></span>
                @*<input type="text" id="Brand" class="layui-input" />*@
            </div>
        </div>
        @*型号*@
        <div class="layui-form-item">
            <label class="layui-form-label">型号</label>
            <div class="layui-input-inline">
                <input type="text" asp-for="XingHao" class="layui-input" />
                <span asp-validation-for="XingHao" style="color: #F56C6C"></span>
                @*<input type="text" id="XingHao" class="layui-input" />*@
            </div>
        </div>
        @*风格*@
        <div class="layui-form-item">
            <label class="layui-form-label">风格</label>
            <div class="layui-input-inline">
                <input type="text" asp-for="FengGe" class="layui-input" />
                <span asp-validation-for="FengGe" style="color: #F56C6C"></span>
                @*<input type="text" id="FengGe" class="layui-input" />*@
            </div>
        </div>
        @*是否组装*@
        <div class="layui-form-item">
            <label class="layui-form-label">是否组装</label>
            <div class="layui-input-inline">
                <select asp-for="ZuZhuang" class="el-input__inner">
                    <option value="">请选择</option>
                    <option value="是">是</option>
                    <option value="否">否</option>
                </select>
                <span asp-validation-for="ZuZhuang" style="color: #F56C6C"></span>
                @*<select id="ZuZhuang">
                        <option value="">请选择</option>
                        <option value="是">是</option>
                        <option value="否">否</option>
                    </select>*@
            </div>
        </div>
        @*颜色*@
        <div class="layui-form-item">
            <label class="layui-form-label">颜色</label>
            <div class="layui-input-inline">
                <input type="text" asp-for="Color" class="layui-input" />
                <span asp-validation-for="Color" style="color: #F56C6C"></span>
                @*<input type="text" id="Color" class="layui-input" />*@
            </div>
        </div>
        @*款式*@
        <div class="layui-form-item">
            <label class="layui-form-label">款式</label>
            <div class="layui-input-inline">
                <input type="text" asp-for="KuanShi" class="layui-input" />
                <span asp-validation-for="KuanShi" style="color: #F56C6C"></span>
                @*<input type="text" id="KuanShi" class="layui-input" />*@
            </div>
        </div>
        @*分类ID外键*@
        <div class="layui-form-item">
            <label class="layui-form-label">分类ID外键</label>
            <div class="layui-input-inline">
                <select asp-for="ProductTypeId" asp-items="@ViewBag.TypeName"></select>
                @*<select id="ProductTypeId">
                        <option value="">请选择</option>
                        @foreach (var item in ViewBag.A)
                        {
                            <option value="@item.Id">@item.Name</option>
                        }
                    </select>*@
                @*<input type="text" id="ProductTypeId" class="layui-input" />*@
            </div>
        </div>
        @*是否显示在首页*@
        <div class="layui-form-item">
            <label class="layui-form-label">是否显示在首页</label>
            <div class="layui-input-inline">
                <select asp-for="HomeFlag" class="el-input__inner">
                    <option value="">请选择</option>
                    <option value="是">是</option>
                    <option value="否">否</option>
                </select>
                <span asp-validation-for="HomeFlag" style="color: #F56C6C"></span>
                @*<select id="HomeFlag">
                        <option value="">请选择</option>
                        <option value="是">是</option>
                        <option value="否">否</option>
                    </select>*@
            </div>
        </div>
        @* 详情 *@
        <div class="layui-form-item">
            <label class="layui-form-label">详情</label>
            <div class="layui-input-block">

                @*<input id="Cont" asp-for="Cont" lay-filter="content" style="display:none;">
                </input>*@
                <input type="text" asp-for="Cont" class="layui-input" />
                <span asp-validation-for="Cont" style="color: #F56C6C"></span>
            </div>
        </div>
        @*提交和重置按钮*@
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="subAdd" lay-submit lay-filter="saveBtn">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>


    </form>
</div>
@section Scripts{
    <script>
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer,
                $ = layui.$;

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                $.post("/Admin/Product/Adddel", data.field, function (re) {
                    if (re.success) {
                        //发异步，把数据提交给
                        layer.alert(re.msg, { icon: 6 }, function () {
                            parent.layui.$("#subAdd").click();
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);

                            //layer.msg(res.msg);
                            //关闭当前窗口，并且刷新列表
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(re.msg);
                    }

                }, "json");

                return false;
            });

        });
    </script>

    @*<script>
        layui.use(['form', 'layedit', 'upload'], function () {
            var form = layui.form;
            var layedit = layui.layedit;
            var upload = layui.upload;
            var $ = layui.$;
            var layer = layui.layer;
            //富文本上传图片
            //layedit.set({
            //    uploadImage: {
            //        url: '/Admin/Product/UploadLayedit', //上传图片的接口url
            //        type: 'post' //默认post
            //    }
            //});
            var index = layedit.build('Cont'); //建立编辑器
            form.verify({
                content: function () {
                    layedit.sync(index);
                }
            })
            //图片上传
            //upload.render({
            //    elem: "#uplaodImg",
            //    url: "/Admin/Product/uploadPhoto",
            //    done: function (res) {
            //        //上传成功
            //        if (res.success == true) {
            //            $("#PicUrl").val(res.path);
            //            $("#imgPhoto").attr("src", "/" + res.path);
            //            layer.msg("上传成功");
            //        } else {
            //            layer.msg("上传失败:" + res.message);
            //        }
            //    }
            //});
            form.on('submit(subAdd)', function () {
                $.ajax({
                    url: "AddDel",
                    method: "post",
                    dataType: "json",
                    data: {
                        Name: $("#Name").val(),
                        PicUrl: $("#uplaodImg").val(),
                        CaiZhi: $("#CaiZhi").val(),
                        ProductPrice: $("#ProductPrice").val(),
                        MarketPrice: $("#MarketPrice").val(),
                        Brand: $("#Brand").val(),
                        XingHao: $("#XingHao").val(),
                        FengGe: $("#FengGe").val(),
                        ZuZhuang: $("#ZuZhuang").val(),
                        Color: $("#Color").val(),
                        KuanShi: $("#KuanShi").val(),
                        HomeFlag: $("#HomeFlag").val(),
                        ProductTypeId: $("#ProductTypeId").val(),
                        Cont: layedit.getContent(index),
                        //Cont: $("#Cont").val(),
                    },
                    success: function (res) {
                        if (res.success == true) {
                            layer.msg(res.msg);
                            //关闭当前窗口，并且刷新列表
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭弹窗
                            parent.layer.close(index);
                            //刷新父页面
                            parent.location.reload();
                        } else {
                            layer.msg(res.msg);
                        }
                    }
                })
            })

        })
    </script>*@
}
